<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="css/demo02.css">
</head>

<body>
<div id="app">
    <div class="header">
        <img src="img/tb.png" alt="">
        <ul>
            <li>网页无障碍</li>
            <li><i class="el-icon-chat-dot-round"></i>登录页面改进建议</li>
        </ul>
    </div>
    <div class="main">
        <img src="img/bj.jpg" alt="">
        <div class="user">
            <div class="name">管理员-密码登录</div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="ruleForm.username"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input type="password" v-model="ruleForm.password"></el-input>
                </el-form-item>
                <el-form-item label="记住密码" prop="state">
                    <el-switch v-model="ruleForm.state"></el-switch>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>

</body>
<script src="js/vue.js"></script>
<script src="js/axios-0.18.0.js"></script>
<script src="element-ui/lib/index.js"></script>
<script src="js/js.cookie.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            ruleForm: {
                username: '',
                password: '',
                state: true,
            },
            rules: {
                username: [
                    {required: true, message: '请输入用户名', trigger: 'blur'},
                    {min: 2, max: 25, message: '长度在 2 到 25 个字符', trigger: 'blur'}
                ],
                password: [
                    {required: true, message: '请输入密码', trigger: 'blur'},
                    {min: 6, max: 25, message: '长度在 6 到 25 个字符', trigger: 'blur'}
                ]
            }
        },
        mounted() {
            this.ruleForm.username = Cookies.get("username")
            this.ruleForm.password = Cookies.get("password")
        },
        methods: {
            submitForm(formName) {
                var _this = this
                _this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post("/taobao/manager/login", _this.ruleForm)
                            .then(resp => {
                                console.log(_this.ruleForm)
                                if (resp.data == "succeed") {
                                    alert("登录成功")
                                    window.location.href = "/taobao/goods.html"
                                } else if (resp.data == "nouser") {
                                    alert("该用户名不存在")
                                } else {
                                    alert("密码错误")
                                }
                            })
                    } else {
                        alert("请按规定格式输入");
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    })
</script>

</html>